<?php
/*
	监听电商客订单状态变更事件
*/
defined('BY_JYA') or exit('error');
$type=$event['type'];
$order=$event['order'];
if(!$type){
	return;
}
if($type=='pay'){
	//付款事件
	$goods=pdo_getall('jy_weishop_order_goods',array('plugin_name'=>'jy_quan','orderid'=>$order['id'],'uniacid'=>$_SESSION['uniacid']),array('price','total','plugin_name','frompid','merchid'));
	foreach($goods as &$item){
		if($item['frompid']){
			$iteminfo=pdo_get('jy_quan_item',array('id'=>$item['frompid'],'uniacid'=>$_SESSION['uniacid']),array('snsid','type','id'));
			$insert=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$_SESSION['uid'],
					'pid'=>$iteminfo['id'],
					'snsid'=>$iteminfo['snsid'],
					'type'=>$iteminfo['type'],
					'orderid'=>0,
					'fromuser'=>$this->session('fromuser'),
					'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_quan_item_jieli',$insert);
			$jid=pdo_insertid();
			//拼团日志：
			$merchid = pdo_getcolumn('jy_merch_user',array('id'=>$item['merchid']),'mid');
			$ordersn = pdo_getcolumn('jy_weishop_order',array('id'=>$order['id']),'ordersn');
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'merchid'=>$merchid,
				'pid'=>$iteminfo['id'],
				'type'=>$iteminfo['type'],
				'fee'=>$item['total']*$item['price'],
				'ordersn'=>$ordersn,
				'status'=>1,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_quan_feelog',$insert);
			$id=pdo_insertid();
			$this->model('commission')->upbossfee($insert);
			pdo_update('jy_quan_item_jieli',array('orderid'=>$id),array('id'=>$jid));
		}
	}
}
if($type=='send_goods'){
	//发货
	
}
if($type=='receive_goods'){
	//收货
	
}
if($type=='complete'){
	//完成
    $feelog= pdo_get('jy_quan_feelog',array('ordersn'=>$order['ordersn'],'uniacid'=>$_SESSION['uniacid']));
    $this->model('commission')->order_complete($feelog);
}
